package com.getan.boot.module.system.repository;

import com.getan.boot.jdbc.repository.GenericRepository;
import com.getan.boot.module.system.entity.RoleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 角色管理
 *
 * @author Bruce.Gong
 * @since 1.0.0-SNAPSHOT
 */
@SuppressWarnings({"SqlNoDataSourceInspection"})
@Mapper
public interface RoleRepository extends GenericRepository<RoleEntity> {

    /**
     * 根据用户ID查询有效的角色
     *
     * @param userId 用户ID
     * @return 角色列表
     */
    @Select("select t.id, t.code from t_sys_role t " +
            "inner join t_sys_user_role d on d.role_id = t.id and t.deleted = 0 and t.status = 0 " +
            "where d.user_id = #{userId}")
    List<RoleEntity> queryRoleByUserId(@Param("userId") Long userId);

}
